<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>请求封装</title>
</head>

<body>
    <div class="box"></div>
    <script src="./lib/axios.min.js"></script>
    <script src="./js/axios.js"></script>
    <script>
        const $axios = function (options) {
            const { url, data } = options
            console.log(options);
            const baseUrl = "https://autumnfish.cn/api"
            return new Promise((resolve, reject) => {
                if (!url) {
                    reject('请传入url')
                }
                axios.get(baseUrl + url, { params: data })
                    .then((res) => {
                        resolve(res)
                    })
                    .catch((error) => {
                        reject(error)
                    });
            })
        }
        // $axios({
        //     url: "/joke/list",
        //     data: {
        //         num: 1
        //     }
        // }).then(res => {
        //     console.log(res);
        // }).catch(err => {
        //     console.log(err);
        // })
        ajaxNative()
        $.ajax({
            url: "/joke/list?num=" + 1,
            success: (res) => {
                console.log(res);
            }
        })
    </script>
</body>

</html>